package main

import (
	"fmt"
)

/*
func intersect(nums1 []int, nums2 []int) []int {
    if len(nums1) > len(nums2) {
        return intersect(nums2, nums1)
    }
    m := map[int]int{}
    for _, num := range nums1 {
        m[num]++
    }

    intersection := []int{}
    for _, num := range nums2 {
        if m[num] > 0 {
            intersection = append(intersection, num)
            m[num]--
        }
    }
    return intersection
}

*/

func intersect(nums1 []int, nums2 []int) []int {
	result := []int{}
	used := []int{}
	flag := false

	for _, value1 := range nums1 {
		for j, value2 := range nums2 {
			for _, in := range used {
				if j == in {
					flag = true
				}
			}
			if value1 == value2 && !flag {
				used = append(used, j)

				result = append(result, value1)
				break
			}
			flag = false
		}
	}
	return result

}

func main() {
	nums1 := []int{3, 1, 2, 2}
	nums2 := []int{1, 1, 2}
	des := intersect(nums1, nums2)
	fmt.Println(des)

}
